package com.irdstudio.efp.esb.service.impl.wsd.finalnotice;

import com.alibaba.fastjson.JSONObject;
import com.irdstudio.basic.framework.core.constant.ESBConstant;
import com.irdstudio.basic.framework.core.exception.ESBException;
import com.irdstudio.basic.framework.core.util.TraceUtil;
import com.irdstudio.efp.esb.common.client.resp.EsbRespServiceBean;
import com.irdstudio.efp.esb.common.constant.EsbBizEnums;
import com.irdstudio.efp.esb.service.bo.req.wsd.finalnotice.FinalApproveNoticeReqBean;
import com.irdstudio.efp.esb.service.bo.resp.wsd.finalnotice.FinalApproveNoticeRespBean;
import com.irdstudio.efp.esb.service.client.ESBClientFactory;
import com.irdstudio.efp.esb.service.facade.wsd.finalnotice.FinalApproveNoticeService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

@Service("finalApproveNoticeService")
public class FinalApproveNoticeServiceImpl implements FinalApproveNoticeService {
    private static Logger logger = LoggerFactory.getLogger(FinalApproveNoticeServiceImpl.class);

    @Override
    public FinalApproveNoticeRespBean finalCreditNotice(FinalApproveNoticeReqBean finalApproveNoticeReqBean) throws ESBException {
        logger.info("======>调用网商贷复审通知接口【" + finalApproveNoticeReqBean.getRqsIdmptntID() + "_30220006_02】开始<======");
        FinalApproveNoticeRespBean finalApproveNoticeRespBean = null;
        TraceUtil.clear();
        try {
            EsbRespServiceBean recvBean = ESBClientFactory.buildClient()
                    .withBody(finalApproveNoticeReqBean)
                    .withTradeNo(ESBConstant.TRADE_NO_30220006)
                    .withScene(ESBConstant.SCENE_NO_02)
                    .create()
                    .sendAndReceive();
            if (EsbBizEnums.RetCodeEnum.SUCCESS.VALUE.equals(recvBean.getSysHead().getRetInfArry().get(0).getRetCd())) {
                finalApproveNoticeRespBean = recvBean.getBody(FinalApproveNoticeRespBean.class);
            } else {
                throw new ESBException(recvBean.getSysHead().getRetInfArry().get(0).getRetMsg());
            }
            logger.info("调用网商贷复审通知接口【30220006_02】结束，返回信息：" + JSONObject.toJSONString(finalApproveNoticeRespBean));
        } catch (Exception e) {
            logger.error("调用网商贷复审通知接口【30220006_02】出现异常：" + e.getMessage());
            throw new ESBException("调用网商贷复审通知接口【30220006_02】出现异常：" + e.getMessage());
        } finally {
            logger.info("======>调用网商贷复审通知接口【" + finalApproveNoticeReqBean.getRqsIdmptntID() + "_30220006_02】结束<======");
        }
        return finalApproveNoticeRespBean;
    }
}